using System;
using System.Collections.Generic;
using System.Web.Mvc;
using AspNetMvc.Services.Events.Interfaces;
using CoreVirtuoso.Config;

namespace AspNetMvc.Services.Events
{
   internal class EventHoursListService : IEventHoursListService
   {
      private IEventHoursListGenerator _eventHoursListGenerator;

      public EventHoursListService(IEventHoursListGenerator eventHoursListGenerator)
      {
         _eventHoursListGenerator = eventHoursListGenerator;
      }

      public List<SelectListItem> GetHoursList()
      {
         var hoursList = GetHoursListWithDummyListItem();

         return hoursList;
      }

      public List<SelectListItem> GetHoursList(int hourToSelect)
      {
         var hoursList = GetHoursListWithDummyListItem();

         var itemToSelect = hoursList.Find(sli => sli.Value == hourToSelect.ToString());

         if (itemToSelect != null)
            itemToSelect.Selected = true;

         return hoursList;
      }

      private List<SelectListItem> GetHoursListWithDummyListItem()
      {
         var hoursList = _eventHoursListGenerator.GetHoursList();

         var dummyListItem = new SelectListItem
                                {Value = DummyItemsConfig.DummyItemValue, Text = ViewStrings.EventsStrings.Hours};
         hoursList.Insert(0, dummyListItem);

         return hoursList;
      }
   }
}